package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseAttrInfo;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: atguigu
 * @create: 2022-12-21 16:14
 */
@RestController//@Controller+@ResponseBody 响应JSON
@RequestMapping("/admin/product")
//@CrossOrigin  //TODO基于注解解决跨域问题
public class BaseCategoryController {

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;


    /**
     * 查询一级分类列表
     *
     * @return
     */
    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1() {
        List<BaseCategory1> list = baseCategoryService.getCategory1();
        return Result.ok(list);
    }

    /**
     * 根据一级分类ID查询二级分类集合
     *
     * @param category1Id 一级分类ID
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable("category1Id") Long category1Id) {
        List<BaseCategory2> list = baseCategoryService.getCategory2(category1Id);
        return Result.ok(list);
    }


    /**
     * 根据二级分类ID查询三级分类集合
     *
     * @param category2Id 二级分类ID
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3> list = baseCategoryService.getCategory3(category2Id);
        return Result.ok(list);
    }


    /**
     * 用户选择三级分类ID，展示选择分类后得到的平台属性列表（包含平台属性值）
     *
     * @param category1Id
     * @param category2Id
     * @return
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id") Long category1Id,
                                                   @PathVariable("category2Id") Long category2Id,
                                                   @PathVariable("category3Id") Long category3Id) {
        List<BaseAttrInfo> baseAttrInfoList = baseAttrInfoService.attrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(baseAttrInfoList);
    }


}
